﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;
using Entity;

namespace CSP.BL
{
    public static class CountryHelper
    {
        public static IEnumerable GetCountriesWithRole(int roleID)
        {
            using (var dc = new CSPEntities())
            {
                var role = dc.Roles.First(p => p.RoleID == roleID);
                var countries = dc.Countries.Where(p=>!p.Disabled).ToArray();

                role.Countries.Load();
                var source = from p in countries
                             select new
                             {
                                 p.CountryID,
                                 p.Name,
                                 Accessable = role.Countries.Contains(p)? "checked" : "",
                             };

                return source.ToArray();
            }
        }

    }
}
